<template>
    <div class="KPI_parent">
        <!-- KPI 指标 -->
        <box-group-wrap pageTitle="KPI 指标" :isShowData="isShowData">
            <template slot="wrapBody">
                <div class="kpiWrap">
                    <div class="kpiItem">
                        <div class="kpiTop">
                            <span>{{ this.avgCallTime }}</span>
                            <div v-if="avgCallTimeDiff > 0" class="item_right">
                                <i class="el-icon-top iconbeg big"></i>
                                <!--<i class="el-icon-plus iconsmell big"></i>-->
                                <b class="big">+{{ this.avgCallTimeDiff }}</b>
                            </div>
                            <div v-else-if="avgCallTimeDiff < 0" class="item_right">
                                <i class="el-icon-bottom iconbeg equal"></i>
                                <b class="equal">{{ this.avgCallTimeDiff }}</b>
                            </div>
                            <div v-else class="item_right">
                                <i class="el-icon-minus equal"></i>
                            </div>
                        </div>
                        <div class="kpiCenter">
                            <p>平均处理时长</p>
                        </div>
                        <div class="kpiBottom">
                            <span>门槛值</span>
                            <span class="ItemNum">{{ this.avgCallTimeKpi }}</span>
                        </div>
                    </div>
                    <div class="kpiItem">
                        <div class="kpiTop">
                            <span>{{ this.workTimeRate }}%</span>
                            <div v-if="workTimeRateDiff > 0" class="item_right">
                                <i class="el-icon-top iconbeg big"></i>
                                <!--<i class="el-icon-plus iconsmell big"></i>-->
                                <b class="big">+{{ this.workTimeRateDiff }}%</b>
                            </div>
                            <div v-else-if="workTimeRateDiff < 0" class="item_right">
                                <i class="el-icon-bottom iconbeg equal"></i>
                                <b class="equal">{{ this.workTimeRateDiff }}%</b>
                            </div>
                            <div v-else class="item_right">
                                <i class="el-icon-minus equal"></i>
                            </div>
                        </div>
                        <div class="kpiCenter">
                            <p>工时利用率</p>
                        </div>
                        <div class="kpiBottom">
                            <span>门槛值</span>
                            <span class="ItemNum">{{ this.workTimeRateKpi }}%</span>
                        </div>
                    </div>
                    <div class="kpiItem">
                        <div class="kpiTop">
                            <span>{{ this.qualityScore }}</span>
                            <div v-if="qualityScoreDiff > 0" class="item_right">
                                <i class="el-icon-top iconbeg big"></i>
                                <!--<i class="el-icon-plus iconsmell big"></i>-->
                                <b class="big">+{{ this.qualityScoreDiff }}</b>
                            </div>
                            <div v-else-if="qualityScoreDiff < 0" class="item_right">
                                <i class="el-icon-bottom iconbeg equal"></i>
                                <b class="equal">{{ this.qualityScoreDiff }}</b>
                            </div>
                            <div v-else class="item_right">
                                <i class="el-icon-minus equal"></i>
                            </div>
                        </div>
                        <div class="kpiCenter">
                            <p>质检得分</p>
                        </div>
                        <div class="kpiBottom">
                            <span>门槛值</span>
                            <span class="ItemNum">{{ this.qualityScoreKpi }}</span>
                        </div>
                    </div>
                </div>
            </template>
        </box-group-wrap>
    </div>
</template>
<script>
import { mapGetters } from 'vuex';
import { MobileNum, base64Encode, getDictSelectList } from 'utils/Common';
import { getToken, removeToken, getTokenHsbankNo } from '@/utils/auth';
import { isEmptyObject } from '@/utils/Object';
import BoxGroupWrap from '@/components/boxgroupwrap/BoxGroupWrap.vue';

export default {
    name: 'kpiIndex',
    data() {
        return {
            isShowData: true,
            kpiIndex: [],
            avgCallTime: '',
            avgCallTimeKpi: '',
            avgCallTimeDiff: '',
            workTimeRate: '',
            workTimeRateKpi: '',
            workTimeRateDiff: '',
            qualityScore: '',
            qualityScoreKpi: '',
            qualityScoreDiff: '',
        }
    },
    components: { 'box-group-wrap': BoxGroupWrap, },
    async mounted() {
        this.kpiIndex = await getDictSelectList('KPI_INDEX', this);
        this.kpiIndex.forEach((item) => {
            if (item.label === '平均处理时长门槛值') {
                this.avgCallTimeKpi = item.code.trim();
            }
            if (item.label === '工时利用率门槛值') {
                this.workTimeRateKpi = item.code.trim() * 100;
            }
            if (item.label === '质检得分门槛值') {
                this.qualityScoreKpi = item.code.trim();
            }
        });
        this.getKpiData();
    },
    methods: {
        getKpiData() {
            const userInfo = JSON.parse(getToken());
            let data = {
                userAccount: userInfo.userAccount,
                userName: userInfo.userName,
                ctiNum: userInfo.ctiNum,
            };
            this.$post.kpi.getKpiDate(data)
                .then((res) => {
                    if (res.data.success) {
                        console.info('res.data.content', res.data.content);
                        this.avgCallTime = res.data.content.avgTime;
                        this.avgCallTimeDiff = this.avgCallTime - this.avgCallTimeKpi;
                        this.workTimeRate = (res.data.content.workTimeRate * 100).toFixed(0);
                        this.workTimeRateDiff = (this.workTimeRate - this.workTimeRateKpi).toFixed(0);
                        this.qualityScore = res.data.content.averageScore;
                        this.qualityScoreDiff = (this.qualityScore - this.qualityScoreKpi).toFixed(0);
                        console.info('workTimeRateDiff:' + this.workTimeRateDiff + ',' + 'qualityScore:' + this.qualityScore + ',' + 'qualityScoreDiff:' + this.qualityScoreDiff);
                    } else {
                        this.$message.error(res.data.msg);
                    }
                });
        },
    },
}
</script>
<style lang="scss">
.KPI_parent {
    .box-group-wrap .trainingMain {
        min-height: 125px;
    }
}
</style>

<style scoped lang="scss">
.kpiWrap {
    margin-top: 10px;
    display: flex;
    .kpiItem {
        flex: 1;
        border: 1px solid #3c9eff;
        border-radius: 7px;
        background-color: #e3f1ff;
        margin: 8px 10px;
        height: 122px;
        text-align: left;
        padding: 5px 0 0 10px;
        .kpiTop {
            line-height: 36px;
            margin-left: 10px;
            margin-top: 3px;
            span {
                font-size: 26px;
                font-weight: bold;
            }
            .item_right {
                width: 50%;
                float: right;
                display: inline-block;
                line-height: 28px;
                margin-top: 5px;
                b {
                    font-size: 16px;
                    margin-left: 5px;
                }
            }
            .iconbeg {
                font-weight: bold;
                font-size: 22px;
            }
            .iconsmell {
                font-size: 14px;
                font-weight: bold;
                margin-left: 15px;
            }
            /* 三种状态的颜色 */
            .equal {
                color: #e85441;
            }
            .big {
                color: #0b925a;
            }
        }
        .kpiCenter {
            line-height: 30px;
            p {
                font-size: 14px;
                font-weight: bold;
            }
        }
        .kpiBottom {
            line-height: 34px;
            span {
                font-size: 14px;
            }
            .ItemNum {
                color: #e85441;
                margin-left: 15px;
            }
        }
    }
}
</style>